#include <stdio.h>
#include <linenoise.h>
#include "cli.h"



void device_handler(int argc , char** argv) {
    printf("device cmd\n");
}

void device_cmd() {
    Command_t device_cmd = {
        .name = "device",
        .description = " set device variable",
        .handler = device_handler,
        .usage = " 设备设置",
        .next = NULL,
    };

    Argument_t device_arg_add = {
        .name = "add",
        .descripute = " dev_name",
        .required = 0, 
        .usage = "添加设备",
        .next = NULL,
    };

    Argument_t device_arg_config = {
        .name = "config",
        .descripute = " config.json",
        .required = 0, 
        .usage = "导入json数据",
        .next = NULL,
    };
    Argument_t device_arg_cag = {
        .name = "cag",
        .descripute = " 123",
        .required = 0, 
        .usage = "参数同开头测试",
        .next = NULL,
    };
    add_command_argment(&device_cmd, &device_arg_add);
    add_command_argment(&device_cmd, &device_arg_config);
    add_command_argment(&device_cmd, &device_arg_cag);
    register_command(&device_cmd);

    Command_t doc_cmd = {
        .name = "doc",
        .description = " doc help",
        .handler = device_handler,
        .usage = " 帮助文档",
        .next = NULL,
    };
    register_command(&doc_cmd);
}

void initialize_commands() {
    device_cmd();
}

int main() {
    char *line;

    initialize_commands();
    initalize_linenoise();

    while ((line = linenoise("edge> ")) != NULL) {
        // printf("line %s\n", line);
        linenoiseHistoryAdd(line);
        execute_command(line);
    }
    linenoiseHistorySave(HISTORY_PATH);
    linenoiseFree(line);
    free_commands();
}